#pragma once
#include "yzrutil.h"
#include "FilterOutputStream.h"


namespace yzrilyzr_io{
	ECLASS(PrintStream, public FilterOutputStream){
	private:
	bool autoFlush=false;
	void write(const yzrilyzr_lang::String & str){
		if(str==nullptr)output->write(U_NULL_STRING.getBytes(yzrilyzr_lang::StringEncoding::UTF8));
		else output->write(str.getBytes(yzrilyzr_lang::StringEncoding::UTF8));
	}
	void newLine(){
		output->write(yzrilyzr_lang::String("\n").getBytes(yzrilyzr_lang::StringEncoding::UTF8));
		if(autoFlush)
			output->flush();
	}
	public:
	PrintStream(OutputStream & out, bool autoFlush) :autoFlush(autoFlush), FilterOutputStream(out){}
	PrintStream(OutputStream & out) :autoFlush(false), FilterOutputStream(out){}
	void println(){
		newLine();
	}
	void println(const Object & object){
		write(object.toString());
		newLine();
	}
	void print(const Object & object){
		write(object.toString());
	}
	void println(const yzrilyzr_lang::String & str){
		write(str);
		newLine();
	}
	void print(const yzrilyzr_lang::String & str){
		write(str);
	}
	};
}